<template>
	<el-dialog title="收藏对话框" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-form-item label="收藏分类" prop="boxId">
				<el-cascader v-model="form.boxId" :options="boxList" :props="bpmCollectProps" :show-all-levels="false" style="width: 100%" clearable></el-cascader>
			</el-form-item>
			<el-form-item label="收藏别名" prop="byName">
				<el-input v-model="form.byName" placeholder="收藏别名" clearable></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="remark">
				<el-input v-model="form.remark" maxlength="150" clearable type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	components: {},
	emits: ['success', 'closed'],
	data() {
		return {
			visible: false,
			isSaveing: false,
			boxList: [],
			bpmCollectProps: {
				value: "boxId",
				label: "boxName",
				emitPath: false,
				checkStrictly: true
			},
			//表单数据
			form: {
				boxId: '',
				model:'0',
				byName: '',
				remark: '',
				runIds: []
			},
			//验证规则
			rules: {
				boxId: [
					{required: true, message: '请选择收藏分类'}
				],
				byName: [
					{required: true, message: '收藏别名不能为空'}
				],
			}
		}
	},
	mounted() {
		this.getBpmCollectBoxForTree();
	},
	methods: {
		//显示
		open() {
			this.visible = true;
			return this
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res = await this.$API.bpm.bpmCollect.createBpmCollect.post(this.form);
					this.isSaveing = false;
					if (res.code == 200) {
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.visible = false;
						this.$alert("有"+res.data.length+"条流程之前已收藏！本次不再重复收藏！", "提示", {type: 'error'})
					}
				}
			})
		},
		async getBpmCollectBoxForTree() {
			var res = await this.$API.bpm.bpmCollect.getBpmCollectBoxForTree.get({model:"0"});
			if (res.code == 200) {
				this.boxList = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		setData(data) {
			this.form.runIds = data
		},
	}
}
</script>

<style>
</style>
